<!DOCTYPE html>
<html lang="zh-cn">
   <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>{$CONF['shopTitle']['fieldValue']}后台管理中心</title>
      <link href="__PUBLIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <link href="__ROOT__/Apps/Admin/View/css/AdminLTE.css" rel="stylesheet" type="text/css" />
      <link rel="stylesheet" href="__ROOT__/Apps/Admin/View/css/daterangepicker/daterangepicker-bs3.css">
      <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.min.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
      <![endif]-->
      <script src="__PUBLIC__/js/jquery.min.js"></script>
      <script src="__PUBLIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
      <script src="__ROOT__/Apps/Admin/View/js/daterangepicker.js"></script>
      <script src="__PUBLIC__/js/common.js"></script>
      <script src="__PUBLIC__/plugins/plugins/plugins.js"></script>
      <script src="__PUBLIC__/plugins/formValidator/formValidator-4.1.3.js"></script>
   </head>
   <script>
   $(function () {
	   $.formValidator.initConfig({
		   theme:'Default',mode:'AutoTip',formID:"myform",debug:true,submitOnce:true,onSuccess:function(){
				   edit();
			       return false;
			},onError:function(msg){
		}});
	   $("#navTitle").formValidator({empty:false,onFocus:"请输入导航名称"}).inputValidator({min:1,max:50,onError: "请输入导航名称"});
	   $('#navUrl').formValidator({empty:false,onFocus:"请输入导航链接"}).inputValidator({min:1,max:100,onError: "请输入导航链接"});
	   <notempty name='object["areaId1"]'>
	   getAreaList("areaId2","{$object['areaId1']}",0,"{$object['areaId2']}");
	   </notempty>
   });
   function getAreaList(objId,parentId,t,id){
	   var params = {};
	   params.parentId = parentId;
	   $('#'+objId).empty();
	   
	   var html = [];
	   $.post("{:U('Admin/Areas/queryByList')}",params,function(data,textStatus){
		    html.push('<option value="">请选择</option>');
			var json = WST.toJson(data);
			if(json.status=='1' && json.list.length>0){
				var opts = null;
				for(var i=0;i<json.list.length;i++){
					opts = json.list[i];
					html.push('<option value="'+opts.areaId+'" '+((id==opts.areaId)?'selected':'')+'>'+opts.areaName+'</option>');
				}
			}
			$('#'+objId).html(html.join(''));
	   });
   }
   function edit(){
	   var params = {};
	   params.id = $('#id').val();
	   params.areaId1 = $('#areaId1').val();
	   params.areaId2 = $('#areaId2').val();
       params.navType = $('#navType').val();
	   params.navUrl = $.trim($('#navUrl').val());
	   params.navTitle = $.trim($('#navTitle').val());
	   params.isShow = document.getElementById('isShow1').checked?1:0;
	   params.isOpen = document.getElementById('isOpen1').checked?1:0;
	   params.navSort = $.trim($('#navSort').val());
	   Plugins.waitTips({title:'信息提示',content:'正在提交数据，请稍后...'});
	   $.post("{:U('Admin/Navs/edit')}",params,function(data,textStatus){
			var json = WST.toJson(data);
			if(json.status=='1'){
				Plugins.setWaitTipsMsg({ content:'操作成功',timeout:1000,callback:function(){
				   location.href="{:U('Admin/Navs/index')}";
				}});
			}else{
				Plugins.closeWindow();
				Plugins.Tips({title:'信息提示',icon:'error',content:json.msg,timeout:1000});
			}
	   });
   }
   function changeFlink(obj){
	   var flink = $(obj).val();

	   if(flink==1){
		   $("#articles").hide();
		   //$("#navUrl").show();
	   }else{
		   $("#articles").show();
		   //$("#navUrl").hide();
	   }
   }
   
   function changeArticles(obj){
	   var url = $(obj).val();
		
	   $("#navUrl").val(url);
   }
   </script>
   <body class="wst-page">
       <form name="myform" method="post" id="myform" autocomplete="off">
        <input type='hidden' id='id' value='{$object["id"]}'/>
        <table class="table table-hover table-striped table-bordered wst-form">
           <tr>
             <th align='right'>导航城市：</th>
             <td>
             <select id='areaId1' onchange='javascript:getAreaList("areaId2",this.value,0)'>
                <option value=''>请选择</option>
                <volist name="areaList" id="vo">
                <option value='{$vo['areaId']}' <if condition="$object['areaId1'] == $vo['areaId'] ">selected</if>>{$vo['areaName']}</option>
                </volist>
             </select>
             <select id='areaId2'>
               <option value=''>请选择</option>
             </select>
             (不选则默认整个商城)
             </td>
           </tr>
           <tr>
             <th width='150' align='right'>导航位置<font color='red'>*</font>：</th>
             <td>
               <select id='navType'>
                 <option value='0' <if condition="$object['navType'] == 0 ">selected</if>>顶部</option>
                 <option value='1' <if condition="$object['navType'] == 1 ">selected</if>>底部</option>
               </select>
             </td>
           </tr>
           <tr>
             <th width='150' align='right'>导航名称<font color='red'>*</font>：</th>
             <td><input type='text' id='navTitle' class="form-control wst-ipt" value='{$object.navTitle}' maxLength='50'/></td>
           </tr>
           <tr>
             <th width='150' align='right'>链接来自：<font color='red'>*</font></th>
             <td>
             	<select id="linkfrom" onchange="changeFlink(this);">
             		<option value="1">外部链接</option>
             		<option value="2">系统文章</option>
             	</select>
             </td>
           </tr>
           <tr>
             <th align='right'>导航链接：</th>
             <td>
            	<select id="articles" style="display:none;" onchange="changeArticles(this)">
             		<volist name="articles" id="vo" key="kv"> 
             			<option value="{:WSTRootDomain()}{:U('Home/Articles/index/',array('articleId'=>$vo['articleId']))}">{$vo["articleTitle"]}</option>
             		</volist>
             	</select>
             	<input type='text' id='navUrl' class="form-control wst-ipt" value='{$object.navUrl}' maxLength='100'/>
             </td>
           </tr>
           <tr>
             <th align='right'>是否显示<font color='red'>*</font>：</th>
             <td>
             <label><input type='radio' id='isShow0' name='isShow' value='0' <if condition="$object['isShow'] eq 0">checked</if>>隐藏</label>
             <label><input type='radio' id='isShow1' name='isShow' value='1' <if condition="$object['isShow'] eq 1">checked</if>>显示</label>
             </td>
           </tr>
           <tr>
             <th align='right'>打开方式<font color='red'>*</font>：</th>
             <td>
             <label><input type='radio' id='isOpen0' name='isOpen' value='0' <if condition="$object['isOpen'] eq 0">checked</if>>页面跳转</label>
             <label><input type='radio' id='isOpen1' name='isOpen' value='1' <if condition="$object['isOpen'] eq 1">checked</if>>新窗口打开</label>
             </td>
           </tr>
           <tr>
             <th align='right'>导航排序号：</th>
             <td>
             <input type='text' id='navSort' class="form-control"  value='{$object.navSort}' style='width:80px' onkeypress="return WST.isNumberKey(event)" onkeyup="javascript:WST.isChinese(this,1)" maxLength='8'/>
             </td>
           </tr>
           <tr>
             <td colspan='2' style='padding-left:250px;'>
                 <button type="submit" class="btn btn-success">保&nbsp;存</button>
                 <button type="button" class="btn btn-primary" onclick='javascript:location.href="{:U('Admin/Navs/index')}"'>返&nbsp;回</button>
             </td>
           </tr>
        </table>
       </form>
   </body>
</html>